<template>
	<view class="main">
		<view class="top">
			<image src="../../static/image/smzr.png" mode=""></image>
			<view class="refresh-btn" @click="doRefresh">
				刷新
			</view>
		</view>
		<view class="nav-wrap uni-flex u-flex-wrap">
			<view @click="skip" class="item uni-flex uni-justify-content-c uni-align-items-c uni-flex-direction-c"
				hover-class="none">
				<image src="../../static/image/brrz.png" mode=""></image>
				<view class="text">
					本人认证
				</view>
			</view>
			<navigator url="./selfCertification?type=others"
				class="item uni-flex uni-justify-content-c uni-align-items-c uni-flex-direction-c" hover-class="none">
				<image src="../../static/image/btrrz.png" mode=""></image>
				<view class="text">
					帮他人认证
				</view>
			</navigator>
			<navigator v-if="show" url="./certificationAudit"
				class="item uni-flex uni-justify-content-c uni-align-items-c uni-flex-direction-c" hover-class="none">
				<image src="../../static/image/rzsp.png" mode=""></image>
				<view class="text">
					认证审核
				</view>
			</navigator>
			<navigator v-if="show" url="./authenticatedList"
				class="item uni-flex uni-justify-content-c uni-align-items-c uni-flex-direction-c" hover-class="none">
				<image src="../../static/image/yrzlb.png" mode=""></image>
				<view class="text">
					已认证列表
				</view>
			</navigator>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				bid: []
			}
		},
		onLoad(options) {
			if (options.id && options.name) {
				let id = options.id;
				let name = decodeURIComponent(options.name);
				name = unescape(name.replace(/\\u/g, '%u')).replace(/['" ]/g, '');
				this.bid = {
					id: id,
					name: name
				};
				uni.setStorageSync('bid', this.bid);
			} else {
				uni.setStorageSync('bid', {
					id: '',
					name: ''
				});
			}
		},
		onShow() {
			let scenne = wx.getLaunchOptionsSync().scene;
			// console.log(scenne, this.bid.id, this.bid.name);
			uni.setStorageSync('scenne', scenne);

			let show = uni.getStorageSync('show');
			this.show = show;
			// 隐藏标题栏左边返回按钮
			if (wx.canIUse('hideHomeButton')) {
				wx.hideHomeButton()
			}
		},
		methods: {
			// 刷新
			doRefresh() {
				uni.clearStorageSync();
				this.$u.toast('刷新中...');
				setTimeout(() => {
					uni.reLaunch({
						url: './login'
					})
				}, 1500);
			},
			// 跳转
			skip() {
				let id = uni.getStorageSync('user').id;
				this.$u.api.userFind({
					id: id
				}).then(res => {
					if (res.code == 0) {
						if (res.data.role == 0 && res.data.status == 0) {
							uni.navigateTo({
								url: './selfCertification?type=self'
							})
						} else if (res.data.role != 0 && res.data.status == 0) {
							uni.navigateTo({
								url: 'resultIng?type=self&id=' + res.data.id
							})
						} else if (res.data.status == 1) {
							uni.navigateTo({
								url: 'resultSuccess?type=self&id=' + res.data.id + '&role=' + res.data
									.role
							})
						} else if (res.data.status == 2) {
							uni.navigateTo({
								url: 'resultFail?type=self&id=' + res.data.id
							})
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		.top {
			text-align: center;
			position: relative;

			image {
				width: 332rpx;
				height: 264.4rpx;
				margin-top: 100rpx;
				margin-bottom: 124rpx;
			}

			.refresh-btn {
				position: absolute;
				right: 28rpx;
				top: 28rpx;
				font-size: 28rpx;
				color: #737373;
			}
		}

		.nav-wrap {
			padding: 0 32rpx;
			box-sizing: border-box;

			.item {
				width: 332rpx;
				height: 300rpx;
				background: #FFFFFF;
				box-shadow: 0 0 4rpx rgba(194, 194, 194, 0.1);
				border-radius: 20rpx;
				margin-bottom: 22rpx;

				image {
					width: 140rpx;
					height: 140rpx;
				}

				.text {
					margin-top: 44rpx;
					font-size: 36rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #333333;
				}
			}

			.item:not(:nth-child(2n)) {
				margin-right: 22rpx;
			}
		}
	}
</style>
